package threeGates;

/**
 * 〈一句话功能简述>
 * 〈三门问题〉
 *
 * @Author 17505
 * @Create 2021/6/8
 * @Since 1.0.0
 */
public class ThreeGatesExperiment {

    private int N;
    private int wins;

    public ThreeGatesExperiment(int N) {
        if (N <= 0) {
            throw new IllegalArgumentException("N must be larger than zero");
        }
        this.N = N;
    }

    public void run(boolean changeDoor) {
        for (int i = 0; i < N; i++) {
            if (play(changeDoor)) {
                wins++;
            }
        }
        System.out.println(changeDoor ? "Change" : "Not Change");
        System.out.println("winning rate:" + (double) wins/N);
    }

    private boolean play(boolean changeDoor) {
        int prizeDoor = (int) (Math.random() * 3);
        int playerChoice = (int) (Math.random() * 3);
        if (playerChoice == prizeDoor)
            return changeDoor ? false : true;
        else
            return changeDoor ? true : false;
    }

    public static void main(String[] args) throws InterruptedException {
        int N = 1000000;
        ThreeGatesExperiment experiment = new ThreeGatesExperiment(N);
        experiment.run(true);
        Thread.sleep(4000);
        experiment.run(false);

    }
}